package uk.ac.nott.cs.g53dia;
import java.util.List;

import javax.swing.Icon;
import javax.swing.ImageIcon;

/**
 * A default implementation of the BeeViewerIconFactory interface.
 * 
 * @author Neil Madden
 */

/*
 * Copyright (c) 2009 Neil Madden.
 * Copyright (c) 2010 University of Nottingham.
 * 
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

public class DefaultBeeViewerIconFactory implements BeeViewerIconFactory {
    static ImageIcon beeIcon;
    static ImageIcon beeIcon2;
    static ImageIcon beeIcon3;
    static ImageIcon beeIcon3al;
    static ImageIcon nestIcon;
    static ImageIcon[] flowerIcon;

    static {
        // Pre-load the images
        beeIcon     = createImageIcon("images/tn_bee.gif");
        beeIcon2    = createImageIcon("images/tn_bee2.gif");
        beeIcon3    = createImageIcon("images/tn_bee3.gif");
        beeIcon3al    = createImageIcon("images/tn_bee3_alpha.png");
        nestIcon    = createImageIcon("images/tn_nest.png");
        flowerIcon  = new ImageIcon[5];
        flowerIcon[0] = createImageIcon("images/tn_flower_blue.png");
        flowerIcon[1] = createImageIcon("images/tn_flower_cyan.png");
        flowerIcon[2] = createImageIcon("images/tn_flower_pink.png");
        flowerIcon[3] = createImageIcon("images/tn_flower_red.png");
        flowerIcon[4] = createImageIcon("images/tn_flower_orange.png");
    }

    protected static ImageIcon createImageIcon(String path) {
        java.net.URL img = DefaultBeeViewerIconFactory.class.getResource(path);
        if (img != null) {
            return new ImageIcon(img);
        } else {
            System.err.println("Couldn't load image: " + path);
            return null;
        }
    }

    public Icon getIconForCell(Cell cell, List<Bee> swarm) { 
        if (cell == null) {
            return null;
        } else if (cell instanceof Flower) {
            Flower f = (Flower)cell;
            return flowerIcon[f.getType()];
        } else if (cell instanceof Nest) {
            return nestIcon;
        } else {
//            for (Bee b : swarm) {
//            	if (b.getPosition().equals(cell.getPoint())) {
//            		return beeIcon;
//            	}
//            }
            return null;
        }
    }

    public Icon getIconForBee(Bee bee) { return beeIcon; }
    public Icon getIconForBee2(Bee bee) { return beeIcon2; }
    public Icon getIconForSmallBee(Bee bee) { return beeIcon3; }
    public Icon getIconForSmallBeeAl(Bee bee) { return beeIcon3al; }

}
